<%# this partial expects the following parameters to be set: -%>
<%# - "resource_type" - type (string value required) of the current resource -%>
<%# - project_hash - hash in a form of { <project_id> => <project_name>, [...] } of all projects that the current user is a member of -%>
<%# - selected_project_id - ID of the project the resource is currently associated with; skip this parameter for a "new" resource -%>
<%# - disable_project_select - selection should only be available on 'new' action, but not on 'edit'; this parameter has a default of "false" -%>

<% selected_project_id ||= 0 -%>
<% disable_project_select ||= false -%>

<% unless project_hash.empty? -%>
	<div style="margin: 1.5em 0 1em 0; text-align: left;">
	  <%= image_tag method_to_icon_filename("spinner"), :id => "policy_loading_spinner", :alt=>"loading...", :title=>"loading...", :style => "display: none; vertical-align: middle; float: right;" -%>
		
		<% front_part_of_msg = (disable_project_select ? "Previously you have chosen to associate this #{resource_type} with the<br/>project below. You are not allowed to change this. Please<br/>contact administrator to amend the association." : "Please choose a project to associate this #{resource_type} with. You will<br/>not be able to amend this association afterwards.") -%>
		<%= help_icon("#{front_part_of_msg}<br/><br/><b>\"Load sharing defaults\"</b> button will reset any sharing<br/>options to default options set by the owner of a selected project.<br/>This will discard any changes you might have made.") -%>
		
		<% unless disable_project_select -%>
		  Associate this <%= resource_type -%> with the following project:
	  <% else -%>
		  This <%= resource_type -%> is associated with the following project:
		<% end -%>
		<br/>
		
		<select name="<%=resource_type.underscore -%>[project_id]" id="project_selector" <%= "disabled" if disable_project_select -%> style="width: 250px; vertical-align: middle; margin: 0.3em 0;">
		  <% project_hash.each do |p| -%>
			  <option value="<%= p[0] -%>" <%= "selected='selected'" if p[0] == selected_project_id -%>><%= h(p[1]) -%></option>
			<% end -%>
		</select>
		<input type="button" value="Load sharing defaults" onclick="javascript:loadDefaultProjectPolicy($('project_selector').options[$('project_selector').selectedIndex].value);" style="vertical-align: middle; margin-left: 0.3em; width: 170px;"/>
	</div>
<% end -%>
